<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>

<jsp:include page="/public/template/header.jsp" />


<style type="text/css">
input.text {
	width: 400px;
}

input.button {
	width: 80px;
}

table,td,tr,th {
	border-style: solid;
	border-width: 1px;
	border-color: black;
	margin: 0;
	border-collapse: collapse;
	padding: 6px;
}

#content {
	padding: 10px;
}

.editButton
{
	width: 100px;
}

.deleteButton
{
	width: 100px;
}

</style>


<div id="content">


	<h1>Resources: List All</h1>

	<button id="newButton" style="position: absolute; width: 100px; height: 40px; margin-bottom: 100px; font-size: large; font: black;">New</button>
	<div style="position: absolute; top: 150px; width: 100%;">
		<table style="position: absolute; width: 90%">
			<tr>
				<th>URI</th>
				<th>RDF Type</th>
				<th>Type</th>
				<th>Edit</th>
				<th>Delete</th>
			</tr>

			<c:forEach items="${resources}" var="rec">
				<tr>
					<td>${rec.uri}</td>
					<td>${rec.rdfType}</td>
					<td>
						<c:choose>
							<c:when test="${rec.isStatic eq true}">static</c:when>
							<c:otherwise>dynamic</c:otherwise>
						</c:choose>
					</td>
					<td><button class="editButton" value="${rec.id}">Edit</button></td>
					<td><button class="deleteButton" name="${rec.uri}" value="${rec.id}">Delete</button></td>
				</tr>
			</c:forEach>
		</table>
	</div>

</div>



<script type="text/javascript">
	$(function() {
		$("#newButton").click(function() {
			var url = "<c:url value='/config/resources/new'/>";
			$(location).attr('href', url);
		});

		$(".deleteButton").click(function() {
			var decisao = confirm("Are you sure? \n Resource " + $(this).attr("name") + " will be permanently deleted!");
			if (decisao) {
				var url = "<c:url value='/config/resources/'/>" + $(this).attr("value") + "/delete";
				$(location).attr('href', url);
			}
		});

		$(".editButton").click(function() {
			var url = "<c:url value='/config/resources/'/>" + $(this).attr("value");
			$(location).attr('href', url);
		});

	});
</script>


<jsp:include page="/public/template/footer.jsp" />
